<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/login.css' />
    <link rel="stylesheet" href="/stylesheets/footer.css">
</head>

<body>
<div >
    <img src="images/mko.jpg" class="titleimg">
</div>
<div class="loginbody">

    <div class="logincard">

        <div class="hvbox">
            <div class="item">
                <p id="name">用户名 ：</p>
            </div>
            <div class="item2">
                <input id="compyname1" placeholder="用户名">
            </div>
        </div>

        <div class="hvbox">
            <div class="item">
                <p id="password">密码 ：</p>
            </div>
            <div class="item2">
                <input id="compyname2" placeholder="密码" type="password">
            </div>
        </div>
        <div class="btn" id="send">
            <p>登 录</p>
        </div>

    </div>

</div>

<% include footer.ejs %>
<script>

    window.onload=function() {

        document.getElementById("send").addEventListener("click", () => {

            let name = document.getElementById("compyname1");
            let password = document.getElementById("compyname2");

            var xhr = null;
            if (XMLHttpRequest) {
                xhr = new XMLHttpRequest();
            }

            let url = "/toLogin?name=" + name.value + "&password=" + password.value;
            xhr.open("POST", url, true);
            xhr.onload = function () {
                var data = xhr.responseText;

                if(JSON.parse(data).status=="OK"){


                    window.location="/manager";

                }else {

                    alert("用户名或密码错误");
                }
            };
            xhr.send();
        });
    }
</script>
</body>
</html>
